<template>
  <div class="module">
    <!-- 按钮 -->
    <div class="btns">
      <el-form size="small" inline style="text-align:center">
        <el-form-item label="名称">
           <el-input v-model="param.name"></el-input>
        </el-form-item>
      <el-form-item>
      <el-button size="small" type="primary" icon="el-icon-search" @click="loadmodule">搜索
      </el-button>
      </el-form-item>
      </el-form>
      <div style="text-align:right">
      <el-button type="primary" size="small" @click="toAndHander">新增</el-button>
        <el-button type="primary" size="small" @click="downloadHandler">导出</el-button>
      </div>
    </div>
    <!-- /按钮 -->
    
    <!-- 表格 -->
    <el-table size="small" :data="module">
      <el-table-column type="index" :index="1" label="序号"></el-table-column>
      <el-table-column label="名称" prop="name" align="center"></el-table-column>
      <el-table-column label="运算法则" prop="algorithm" align="center"></el-table-column>
      <el-table-column label="简介" prop="introduce" align="center"></el-table-column>
      <el-table-column label="状态" prop="status" align="center"></el-table-column>
      <el-table-column label="发布时间" prop="createTime" align="center"></el-table-column>
      <el-table-column label="applicationId" prop="applicationId" align="center"></el-table-column>
      <el-table-column label="用户Id" prop="userId" align="center"></el-table-column>
      <el-table-column label="datasetId" prop="datasetId" align="center"></el-table-column>
            <el-table-column label="操作" width="130" align="center">
        <!-- 定制-插槽 -->
        <template slot-scope="scope">
                      <el-button type="text" size="mini" icon="el-icon-edit" @click="editHandler(scope.row)" >修改</el-button >
          <el-button type="text" style="color:red" size="mini" icon="el-icon-edit" @click="deleteHandler(scope.row)">删除</el-button
          >
        </template>
      </el-table-column>

    </el-table>
    <!-- /表格 -->
  </div>
</template>
<script>
import {del,get} from '@/utils/request'
export default {
  // 页面数据
  data(){
    return {

      param:{},
      module:[]
    }
  },
  // 页面渲染的时候会调用的函数
  created(){
    this.loadmodule();
  },
  // 所有的方法
  methods:
  {
    downloadHandler(){
      window.location.href="http://8.131.68.179:9999/greenhouse_module/download?name="+this.param.name
    },
  
          editHandler(row){
      // 跳转到修改页面 （新增页面）
      // 携带当前行的数据
      this.$router.push({
        path:"/module/create",    //跳转的路由（前端）
        query:row   // 携带参数
      })
    },
      deleteHandler(row) {
      this.$confirm("此操作将永久删除该数据, 是否继续?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      }).then(() => {
        let url = "http://8.131.68.179:9999/greenhouse_module/deleteByID";
        del(url, { id: row.id }).then((resp) => {
          this.$message({ type: "success", message: resp.message });
          this.loadmodule();
        });
      });
    },


    toAndHander(){
        this.$router.push("/Module/create")
    },
    loadmodule(){
      let url = 'http://8.131.68.179:9999/greenhouse_module/query'
      get(url,this.param).then((resp)=>{
        this.module = resp.data;
      })
    }
  }
}
</script>
<style scoped>
.btns{
    margin-bottom: .5em;
    margin-left: .10em;
}

</style>